class AddCaches < ActiveRecord::Migration
  def self.up
    add_column :runners, :distance_cache, :decimal, :default => 0, :precision => 10, :scale => 2
    add_column :runners, :sessions_cache, :integer, :default => 0

    add_column :groups, :distance_cache, :decimal, :default => 0, :precision => 10, :scale => 2
    add_column :groups, :sessions_cache, :integer, :default => 0
    add_column :groups, :goal_cache, :decimal, :default => 0, :precision => 10, :scale => 2
    add_column :groups, :runners_cache, :integer, :default => 0

    add_column :sites, :distance_cache, :decimal, :default => 0, :precision => 10, :scale => 2
    add_column :sites, :sessions_cache, :integer, :default => 0
    add_column :sites, :goal_cache, :decimal, :default => 0, :precision => 10, :scale => 2
    add_column :sites, :runners_cache, :integer, :default => 0
    add_column :sites, :groups_cache, :integer, :default => 0

    add_column :programs, :distance_cache, :decimal, :default => 0, :precision => 10, :scale => 2
    add_column :programs, :sessions_cache, :integer, :default => 0
    add_column :programs, :goal_cache, :decimal, :default => 0, :precision => 10, :scale => 2
    add_column :programs, :runners_cache, :integer, :default => 0
    add_column :programs, :groups_cache, :integer, :default => 0
    add_column :programs, :sites_cache, :integer, :default => 0
  end

  def self.down
    remove_column :runners, :distance_cache
    remove_column :runners, :sessions_cache

    remove_column :groups, :distance_cache
    remove_column :groups, :sessions_cache
    remove_column :groups, :goal_cache
    remove_column :groups, :runners_cache

    remove_column :sites, :distances_cache
    remove_column :sites, :sessions_cache
    remove_column :sites, :goal_cache
    remove_column :sites, :runners_cache
    remove_column :sites, :groups_cache

    remove_column :programs, :distance_cache
    remove_column :programs, :sessions_cache
    remove_column :programs, :goal_cache
    remove_column :programs, :runners_cache
    remove_column :programs, :groups_cache
    remove_column :programs, :sites_cache
  end
end
